<?php
/* @var $this SiteController */

$this->pageTitle=Yii::app()->name;
?>

<script>
	var validator = null;

	$(document).ready(function() {
		 $("#birthday").kendoDatePicker({
			  format: "yyyy/MM/dd"
		 });

		 validator = $("#form").kendoValidator().data("kendoValidator");

		 $("#file").kendoUpload({
			async: {
				saveUrl: "<?php echo Yii::app()->baseUrl ?>/utility/upload",
				removeUrl: "<?php echo Yii::app()->baseUrl ?>/utility/remove",
				autoUpload: true
			},
			multiple : false,
            showFileList: false,
			success: upload_success
		});
	});

	function upload_success(e){
		if(e.operation == "upload")
		{
			if(e.response.status == "success")
			{
				$("#_file").val(e.response.path);
				$("#image").attr("src", "<?php echo Yii::app()->baseUrl ?>" + e.response.path);
			}
		}
		else if(e.operation == "remove")
		{
			if(e.response.status == "success")
			{
				$("#_file").val("");				
			}
		}
	}
	
	function submit_click(){
		return validator.validate();
	}
</script>

<form id="form" method="post" action="<?php echo Yii::app()->request->baseUrl; ?>/sample/create<?php echo $model -> id ? "?id=" . $model -> id : ''?>">
	<table>
		<tr>
			<td style="width:100px">Username</td>
			<td><input type="text" class="k-textbox" name="User[username]" value="<?php echo $model -> username?>" required validationMessage="Username is required !"/></td>
		</tr>
		<tr>
			<td>Password</td>
			<td><input type="password" class="k-textbox" name="User[password]" value="<?php echo $model -> password?>" required validationMessage="Password is required !"/></td>
		</tr>
		<tr>
			<td>First name</td>
			<td><input type="text" class="k-textbox" name="User[firstname]" value="<?php echo $model -> firstname?>" required validationMessage="First name is required !"/></td>
		</tr>
		<tr>
			<td>Last name</td>
			<td><input type="text" class="k-textbox" name="User[lastname]" value="<?php echo $model -> lastname?>" required validationMessage="Last name is required !"/></td>
		</tr>
		<tr>
			<td>Birthday</td>
			<td><input type="text" name="User[birthday]" id="birthday" value="<?php echo $model -> birthday?>"/></td>
		</tr>
		<tr>
			<td>Upload image</td>
			<td>
				<input type="hidden" name="User[imageUrl]" id="_file"/>
				<table>
					<tr>
						<td><input name="file" id="file" type="file" /></td>
						<td><img id="image" style="max-width:300px; max-height:300px;" src="<?php echo $model -> imageUrl != "" ? Yii::app()->request->baseUrl . "/images/card/" . $model -> imageUrl : ""?>"/></td>
					</tr>
				</table>
			</td>
		</tr>
		<tr>
			<td colspan="2">
				<button class="k-button" onclick="return submit_click();">Submit</button>
			</td>
		</tr>
	</table>
</form>
